package com.quanquan.user.service;

import com.quanquan.user.entity.TaskRecord;
import com.quanquan.user.repository.TaskRecordRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import utils.DateUtils;
import utils.UUIDGenerator;

@Service
public class TaskRecordService {


    @Autowired
    private TaskRecordRepository taskRecordRepository;
    /**
     * 新增任务记录
     * @param userId
     * @param taskType
     * @return
     */
    public void addTaskRecord(String userId,String taskType){
        TaskRecord taskRecord = taskRecordRepository.findByUserId(userId);
        if(taskRecord == null){
            TaskRecord taskRecord1 = new TaskRecord();
            taskRecord1.setId(UUIDGenerator.getUUID());
            taskRecord1.setCreateTime(DateUtils.currentDate());
            if(taskType.equals("sign")){
                taskRecord.setSign(1);
            }else {
                taskRecord.setSign(0);
            }
            if (taskType.equals("selfHelpIntegral")) {
                taskRecord.setSelfHelpIntegral(1);
            }else {
                taskRecord.setSelfHelpIntegral(0);
            }
            if (taskType.equals("parking")) {
                taskRecord.setParking(1);
            }else {
                taskRecord.setParking(0);
            }
        }else{
            if(taskType.equals("sign")){
                taskRecord.setSign(1);
            }
            if (taskType.equals("selfHelpIntegral")) {
                taskRecord.setSelfHelpIntegral(1);
            }
            if (taskType.equals("parking")) {
                taskRecord.setParking(1);
            }
        }
        taskRecordRepository.save(taskRecord);

    }



}
